/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* Copyright(c) 2010 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------
  Nuvoton Technoledge Corp creadted by PU20
  XTAL = 12MHz, BPS = 115200
 *-----------------------------------------------------------------------------*/
/*
//-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
//
// <e0> Clock Configuration
//   <h> Enable Clock Source (PWRCON)
//                  <q1.0> Crystal 12MHz
//            <q1.3> Internal RC 10kHz
//                  <q1.2> Internal RC 22MHz
//   </h>
// <e2> Enable PLL (PLLCON)
//    <o3.19> PLL Clock Source Selection
//                  <0=> Crystal 12MHz        <1=> Internal RC 22MHz
// </e2>
//    <o4.0..2> HCLK System Clock Source Selection (CLKSEL0)
//                  <0=> Crystal 12MHz
//                  <2=> PLL Clock            <3=> Internal RC 10KHz
//                  <4=> Internal RC 22MHz
// </e0>
//-------- <<< end of configuration section >>> ------------------------------
*/
#include "include.h"
#include "command_table.h"
#include "DeviceBtj_Header.h"
#include "sys_types.h"
#include "sys_config.h"
#include "tra_uart.h"
//static DEVICEBTJ_ADAPTER_T btj_adapter;
//static DEVICEBTJ_SERVICE_T spp_service;
//static DEVICEBTJ_SERVICE_T hid_service;
//static DEVICEBTJ_SERVICE_T pnp_service;
DEVICEBTJ_ADAPTER_P bt_adapter;
DEV_MEM_ADDR pair_device_addr = {0};
volatile u_int8 flag_system_active = FALSE;
volatile u_int8 flag_key_down = FALSE;
volatile u_int8 auto_connect_status,connet_flag;
u_int8 enter_sniff_flag,enter_sleep_flag;
u_int8 hid_mode_flag,bluetooth_ssp_mode;
u_int8 pin_code_req;
u_int8 linkkey_buff[LINK_KEY_SAVE_BUF_LEN];
u_int8 spp_mode_sleep_request;
u_int8  bt_link_index;
u_int16 timer_tick1, timer_tick2,timer_tick3;
u_int8 uart_open;
u_int32 sys_flag=0;
void delay_ms(unsigned int tt)
{
    unsigned int i,j;
    while(tt--)
    {
        for (j=0; j<1000; j++)
        {
            for (i=0; i<12; i++)
            {
                ;
            }
        }
    }
}
void send_HCI_command(const unsigned char *buffer,unsigned char data_len)
{
    u_int8 i;
#ifdef UART_LOG
    u_int32 length1 = data_len;
    u_int32 length2 = 4;
    u_int8 buffer3[4] = {0x0B,0x0B,0x0A,0x0A};
    u_int8* buffer2 = &buffer3[0];
#endif
    for (i = 0; i < data_len; i++)
    {
        TRAhcit_UART_Rx_Char(buffer[i]);
    }
#ifdef UART_LOG
    if(1)//(uart_open)
    {
        while(length2)
        {
            uart_buff_send((volatile u_int8**)&buffer2, (u_int32*)&length2);
        }
        while(length1)
        {
            uart_buff_send((volatile u_int8**)&buffer, (u_int32*)&length1);
        }
    }
#endif
}
#if 0
void bt_work_mode_get()
{
    u_int8 i;
    ENV_CONFIG_P config=(ENV_CONFIG_P)env_config_buff;
    bluetooth_ssp_mode=config->ssp_enable;
    if(config->work_mode_selet==2)
    {
        hid_mode_flag=0;
    }
    else
    {
        hid_mode_flag=1;
    }
    for(i=0; i<16; i++)
    {
        if(config->pincode[i]!=0x00)
        {
            btj_adapter.pin_context.pin_buffer[i]=config->pincode[i];
            btj_adapter.pin_context.pin_length++;
        }
        else
        {
            break;
        }
    }
}
#endif
void SYS_Host_Initialise(void)
{
    
}
void enter_sniff(void)
{
    
}
void exit_sniff(void)
{
    
}

void connect_ind()
{
}
void disconnect_ind(void)// for warning messge change
{
}
void status_control(
    DEVICEBTJ_ADAPTER_P Adapter,
    DEVICEBTJ_SERVICE_P Service)
{
    //ENV_CONFIG_P config=(ENV_CONFIG_P)env_config_buff;// for warning messge change
}
void
DeviceBtj_Event(
    DEVICEBTJ_ADAPTER_P MsgAdapter,
    DEVICEBTJ_SERVICE_P MsgService,
    BTBYTE  MsgEvent,
    BTBYTE  MsgState,
    BTPBYTE MsgBuffer,
    BTWORD  MsgLength
)
{
}
BTBOOL
DeviceBtj_Adapter_Write(
    DEVICEBTJ_ADAPTER_P adapter,
    BTPBYTE buffer,
    BTWORD length
)
{
   return 0;
}

DEVICEBTJ_SERVICE_P
DeviceBtj_Adapter_GetService(
    DEV_MEM_ADDR DevMemAddr
)
{
    
    return BTNULL;
}
void Device_HCI_Rx(u_int8 *head_buf, u_int32 head_len, u_int8 *pdu_buf, u_int32 pdu_len)
{
    
}
u_int16 loop_cnt=0;
void FAST_CALL Host_Loop()
{
    //static u_int16 uart_rx_buff_temp;// for warning messge change
    //static u_int8 uart_rx_buff_cnt,uart_rx_buff_cnt_temp;// for warning messge change
}
